package com.example.demo.util;

import javax.servlet.http.HttpServletRequest;

public class IPUtil {

    public static String getClientIpAddress(HttpServletRequest request) {
        if (request == null) return null;
        String xfHeader = request.getHeader("X-Forwarded-For");
        if (xfHeader!= null) {
            return xfHeader.split(",")[0];
        }
        return request.getRemoteAddr();
    }
}
